package com.xlh.dto.course;

import cn.hutool.core.date.DateUtil;
import com.xlh.service.statistic.impl.StatisticServiceimpl;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * @author sy
 * 章节理论课程统计功能
 */
@Data
@Accessors(chain = true)
public class TheoryChapterLeanTimeStatisticsDTO {


    /**
     * 课程ID
     */
    private Long courseId;

    /**
     * 章节ID
     */
    private Long chapterId;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户名称
     */
    private String userName;

    /**
     * 视频时长
     */
    private BigDecimal videoTime;

    /**
     * 学习时长
     */
    private Long learnTime;


    /**
     * 视频总时长 小时
     */
    private BigDecimal videoTimeHour;

    /**
     * 学习总时长 小时
     */
    private Double learnTimeHour;


    /**
     * 视频时长 字符串类型 时：分：秒
     */
    private String videoTimeStr;

    /**
     * 学习时长 字符串类型 时：分：秒
     */
    private String learnTimeStr;

    /**
     * 设置视频时间Str
     */
    public void setVideoTimeStr(){

        if(videoTime == null) {
            this.videoTimeStr = StatisticServiceimpl.convertTime(0l);
            return;
        }
        this.videoTimeStr = StatisticServiceimpl.convertTime(videoTime.longValue());
    }

    /**
     * 设置秒级别
     */
    public void setLearnTimeStr(){

        if(learnTime == null) {
            this.learnTimeStr = StatisticServiceimpl.convertTime(0l);
            return;
        }
        this.learnTimeStr = StatisticServiceimpl.convertTime(learnTime);
    }

    public void setVideoTimeHour() {

        if(videoTime == null) {
            this.videoTimeHour = new BigDecimal(0);
            return;
        }
        this.videoTimeHour = videoTime.divide(new BigDecimal("3600"), 2 , BigDecimal.ROUND_HALF_UP);
    }

    public void setLearnTimeHour() {

        if(learnTime == null) {
            this.learnTimeHour = 0d;
            return;
        }
        this.learnTimeHour =  ((Math.round(Double.valueOf(learnTime)/3600 *100)) / 100.0);
    }

}
